package cn.antsing.config;

import cn.antsing.entity.Cat;
import cn.antsing.entity.User;
import cn.antsing.factory.UserFactory;
import cn.antsing.factoryBean.UserFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * 注解式配置类--功能类似xml配置文件
 *      bean装配方式有2种
 */
@Configuration
public class BeanConfiguration {
    /**
     * bean的装配方式一
     * @return
     */
    //bean的名称默认是方法名-getUserBean，默认单例的
    @Bean(name = "user")
    @Scope(value = "prototype")
    public User getUserBean(){
        User user = new User();
        return user;
    }

    /**
     * bean的装配方式二
     * @return
     */
    @Bean
    public UserFactoryBean getUserFactoryBean(){
        return new UserFactoryBean();
    }

    @Bean
    public UserFactory getUserFactory(){
        return new UserFactory();
    }
    @Bean
    public User getUserByUserFactory(UserFactory userFactory){
        return userFactory.createUser();
    }

    @Bean
    public Cat getCat(){
        return new Cat();
    }
}
